package eg.com.itiga.business.itian;

import java.util.Hashtable;
import java.util.List;

import eg.com.itiga.business.itian.ItianService;

import eg.com.itiga.business.base.BaseServiceImpl;
import eg.com.itiga.business.exception.BusinessException;
import eg.com.itiga.domain.Department;
import eg.com.itiga.domain.Itian;
import eg.com.itiga.repository.base.BaseDao;
import eg.com.itiga.repository.exception.DataException;
import eg.com.itiga.repository.factory.RepositoryFactory;
import eg.com.itiga.repository.itian.ItianDao;

public class ItianServiceImpl extends BaseServiceImpl implements ItianService {

	public List<Itian> SearchItian(String name, int dept, int intake)
			throws BusinessException {
		// TODO Auto-generated method stub
		ItianDao itianDao = null;
		try {
			itianDao = RepositoryFactory.createItianDao();
			itianDao.beginTransaction();
			return itianDao.searchItian(name, dept, intake); 
			
		} catch (DataException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null ;
	}
	
	public List<Itian> getWorkingItians() throws BusinessException 
	{
		List<Itian> itiansList = null;
		ItianDao itianDao = null;
		try {
			itianDao = RepositoryFactory.createItianDao();
			itianDao.beginTransaction();
			
			itiansList = itianDao.getWorkedItians();
			
			itianDao.commit();
		} catch (DataException e) {
			e.printStackTrace();
			
			throw new BusinessException("Couldn't retrive the working itians");
		}
		return itiansList ;
	}

	public List<Department> getAllDepartment() throws BusinessException {
		// TODO Auto-generated method stub
		ItianDao itianDao = null ;
		// List<De>
		try {
			itianDao = RepositoryFactory.createItianDao();
			itianDao.beginTransaction();
			return itianDao.getAllDepartment();
			
			
		} catch (Exception e) {
			// TODO: handle exception
		}
		return null;
	}

	public Itian retriveITIanData(int id) throws BusinessException {

		Itian i = null;
		try {
			ItianDao itianDao = RepositoryFactory.createItianDao();
			// BaseDao bdObject=RepositoryFactory.createBaseDao();

			itianDao.beginTransaction();
			i = itianDao.retriveITIanData(id);
			itianDao.commit();
			if (i != null)
				System.out.println("i not null");
		} catch (DataException ds) {
			ds.printStackTrace();
			System.out.println("you logined and try to view the itian profile");
		}
		return i;

	}

	public Itian getUserData(int u) throws BusinessException {
		// TODO Auto-generated method stub
		ItianDao itianDao = null;
		Itian itian = new Itian();
		try {
			itianDao = RepositoryFactory.createItianDao();
			itianDao.beginTransaction();
			itian = itianDao.getUserData(u);// searchItian(name, dept, intake);
			itianDao.commit();
			return itian;
		} catch (DataException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}

}
